﻿
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Windows.Forms


Public Class Form3
    Private dataAdapter As New SqlClient.SqlDataAdapter()
    Private bindingSource1 As New BindingSource()

    Private Sub Form3_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        My.Settings.Form3Size = Me.Size
        My.Settings.Form3Pos = Me.Location
    End Sub


    Private Sub Form4_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


        DevExpress.UserSkins.OfficeSkins.Register()

        ' Bind the DataGridView to the BindingSource
        ' and load the data from the database.
        Me.Size = My.Settings.Form3Size
        FormPos(My.Settings.Form3Pos)
        Me.Location = My.Settings.Form3Pos

        Me.DataGridView1.DataSource = Me.bindingSource1
        GetData("SELECT * FROM F0002")

    End Sub

    Function GetData(ByVal selectCommand As String)

        Try

            Dim sqlConnection1 As New System.Data.SqlClient.SqlConnection(My.Settings.CADISConnectionString)
            Dim cmd As New System.Data.SqlClient.SqlCommand
            Dim reader As SqlClient.SqlDataReader = Nothing

            cmd.CommandText = selectCommand
            cmd.Connection = sqlConnection1

            Me.dataAdapter = New SqlClient.SqlDataAdapter(cmd)
            Dim commandBuilder As New SqlClient.SqlCommandBuilder(Me.dataAdapter)

            Dim table As New DataTable()
            table.Locale = System.Globalization.CultureInfo.InvariantCulture
            Me.dataAdapter.Fill(table)
            Me.bindingSource1.DataSource = table



            ' Resize the DataGridView columns to fit the newly loaded content.
            Me.DataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells)
        Catch ex As OleDbException

        End Try
        GetData = ""

    End Function



   


    Private Sub BarButtonItem1_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
        Me.dataAdapter.Update(CType(Me.bindingSource1.DataSource, DataTable))
    End Sub
End Class